package com.dragon.smtp.dao;

import com.dragon.smtp.domain.Mail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 小龙
 * @since 2022-11-08
 */
@Mapper
public interface MailDao extends BaseMapper<Mail> {

    @Select("select * from mail where  to_name =#{username} and draft=0 and deleted =0;")
    List<Mail> getMailByToName(String username);
    //获取已发送邮件
    @Select("select * from mail where  from_name =#{username};")
    List<Mail> getMailByFromName(String username);
    //获取发给我邮件的人
    @Select("select from_name from mail where  to_name =#{username};")
    List<String> getFromByTo(String username);
    //获取我发给邮件的人
    @Select("select to_name from mail where  from_name =#{username};")
    List<String> getToByFrom(String username);
    //返回带删除标记的邮件
    @Select("select * from mail where  to_name =#{username} and deleted=1;")
    List<Mail> getDeletedMailByToName(String username);

    @Update("update mail set flag=1 where id=#{id}")
    int startMail(String id);

    //标记删除
    @Update("update mail set deleted=1 where id=#{id}")
    int markDeleteMail(String id);
    //恢复删除
    @Update("update mail set deleted=0 where id=#{id}")
    int restoreDeleteMail(String id);

    @Update("update mail set flag=0 where id=#{id}")
    int unstartMail(String id);

    @Select("select * from mail where  to_name =#{username} and flag=1 and draft=0 and deleted =0;")
    List<Mail> getStarMailByToName(String username);

    @Select("select * from mail where  from_name =#{username} and draft=1 and deleted=0 ;")
    List<Mail> getDraftMailByToName(String username);
}
